package commands;

import core.UserManager;
import user.User;
import messages.Message;
import messages.WallMessage;
import event.WallEventArgs;


/**
 * The Wall command.
 * 
 * This command will handle Wall messages.
 */
public class WallCommand extends Command {

	
	public WallCommand(Message message, User user) {
		super(message, user);
	}
	
	
	@Override
	public void execute() {
		UserManager userManager = controller.getUserManager();
		WallMessage message = (WallMessage) this.message;
		String senderLogin = message.getSenderLogin();
		
		synchronized (userManager) {
			
			if (userManager.isLoggedIn(senderLogin)) {	
				// Notifies all the other participants about this message.
				
				System.err.println("firing wall event...");
				
				this.controller.fireWallEvent(new WallEventArgs(this.message));
			} else {
				// TODO: The sender is not online / doesn't exists!
			}
		}
	}
}
